# -*- coding:utf-8 -*-
import web, models, service
from baseHandler import BaseHandler
from utils.decorator import render

class Statistics(BaseHandler):
    @render('index.html')
    def GET(self, branchCompanyId = None):
        user = self.getCurrentUser()
        if branchCompanyId:
            branchCompanyId = long(branchCompanyId)
            service.Company.getBranchCompany(branchCompanyId)
        hasOverviewRight = service.User.hasOverviewRight(user)
        if not hasOverviewRight and branchCompanyId != user.company_id:
            raise web.seeother('/%d' % user.company_id)
        branchCompanys = models.Company.getBatchByType(models.Company.TYPE_BRANCH) if hasOverviewRight else [models.Company.getById(user.company_id)]

        return {'title' : u'首页', 'branch_companys' : branchCompanys, 'statistics' : service.Case.getStatistics(branchCompanyId), 'active_company_id' : branchCompanyId, 'active_type' : 'statistics', 'can_overview' : hasOverviewRight}